var cc__decorate = __decorate;
var cc__awaiter = __awaiter;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2gameBefore = require("gameBefore");
var $2GameUser = require("GameUser");
var $2EventCenter = require("EventCenter");
var $2EventDefine = require("EventDefine");
var $2InteractiveMgr = require("InteractiveMgr");
var $2UIManager = require("UIManager");
var $2MiniPlatform = require("MiniPlatform");
var $2Platformconf = require("Platformconf");
var $2ccUtil = require("ccUtil");
var $2BaseUIPopup = require("BaseUIPopup");
var $2UIVMain = require("UIVMain");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_UIPfree = /* */function (_f$default2) {
  function _ctor() {
    var _this120;
    babel_classCallCheck(this, _ctor);
    _this120 = _callSuper(this, _ctor, arguments);
    _this120.root = null;
    _this120.libao = null;
    _this120.yaoqing = null;
    _this120.scroller1 = null;
    _this120.invite = 0;
    _this120.lingqu = 0;
    _this120.unlock5 = false;
    _this120.scroll_content = null;
    _this120.tili4 = null;
    _this120.icon = null;
    _this120.tag_rectYXQ = null;
    _this120.yxqBtn = null;
    return _this120;
  }
  babel_inherits(_ctor, _f$default2);
  return babel_createClass(_ctor, [{
    key: "onShow",
    value: function onShow() {
      var _this121 = this;
      babel_get(babel_getPrototypeOf(_ctor.prototype), "onShow", this).call(this);
      this.init();
      $2UIManager.UIManager.getInstance().getUI($2UIVMain.default).isHome && $2Platformconf.default.PlatformType === $2Platformconf.ePlatformType.WXGame && cc.Canvas.instance.node.getComponent($2gameBefore.default).BannerShow();
      $2Platformconf.default.PlatformType;
      $2Platformconf.ePlatformType.WXGame;
      null != $2UIManager.UIManager.getInstance().getUI($2UIVMain.default) && $2UIManager.UIManager.getInstance().getUI($2UIVMain.default).hideYXQ();
      this.unlock5 = $2GameUser.default.getInstance().getUnlocktili("5");
      if (!this.unlock5) {
        this.scroller1.node.on("scroll-ended", this.onScroller_end, this);
        this.scroller1.node.on("scroll-began", this.onScroller_began, this);
        this.scheduleOnce(function () {
          var e = _this121.convertToWXRect(_this121.tag_rectYXQ);
          _this121.createYXQBtn(e);
        });
      }
      $2EventCenter.default.regisEvent("uipfree", this.init, this);
    }
  }, {
    key: "onDestroy",
    value: function onDestroy() {
      babel_get(babel_getPrototypeOf(_ctor.prototype), "onDestroy", this).call(this);
      $2EventCenter.default.removeEvent("uipfree", this.init, this);
      this.yxqBtn && this.yxqBtn.destroy();
    }
  }, {
    key: "onScroller_began",
    value: function onScroller_began(e, t) {
      $2GameUser.default.getInstance().getUnlocktili("5") || this.yxqBtn && this.yxqBtn.hide();
    }
  }, {
    key: "onScroller_end",
    value: function onScroller_end(e, t) {
      if (!$2GameUser.default.getInstance().getUnlocktili("5")) {
        var _e65 = this.convertToWXRect(this.tag_rectYXQ);
        this.createYXQBtn(_e65);
      }
    }
  }, {
    key: "click",
    value: function click(e, t) {
      var _this122 = this;
      babel_get(babel_getPrototypeOf(_ctor.prototype), "click", this).call(this, e, t);
      var n = e.getCurrentTarget();
      if ("close" == t) {
        null != $2UIManager.UIManager.getInstance().getUI($2UIVMain.default) && $2UIManager.UIManager.getInstance().getUI($2UIVMain.default).showYXQ();
        this.close();
        $2UIManager.UIManager.getInstance().getUI($2UIVMain.default).initred();
      } else if ("close2" == t) {
        this.libao.active = false;
      } else if ("choose" == n.name) {
        var _e66 = n.parent.name;
        if ("0" == _e66) {
          $2MiniPlatform.default.Instance.shareAppMessage(function (e) {
            if (true === e) {
              n.active = false;
              console.log("分享成功");
              $2GameUser.default.getInstance().setUnlocktili("0", true);
              _this122.root.getChildByName("0").getChildByName("choose2").active = true;
            }
          }, {});
        } else if ("1" == _e66 || "2" == _e66 || "3" == _e66) {
          this.libao.active = true;
          this.init_libao(_e66);
        } else if ("4" == _e66) {
          $2MiniPlatform.default.Instance.shareAppMessage(function (e) {
            true === e && console.log("分享成功");
          }, {});
        } else {
          "6" == _e66 && $2MiniPlatform.default.Instance.shareAppMessage(function (e) {
            if (true === e) {
              n.active = false;
              console.log("分享成功");
              $2GameUser.default.getInstance().setUnlocktili("6", true);
              _this122.root.getChildByName("6").getChildByName("choose2").active = true;
            }
          }, {});
        }
      } else if ("choose2" == n.name) {
        var _e67 = n.parent.name;
        if ("0" == _e67) {
          $2GameUser.default.getInstance().setUnlocktili("get0", true);
          n.active = false;
          n.parent.getChildByName("b").active = true;
          this.tiliFly(1);
        } else if ("1" == _e67) {
          $2GameUser.default.getInstance().setUnlocktili("get1", true);
          n.active = false;
          n.parent.getChildByName("b").active = true;
          this.tiliFly(1);
        } else if ("2" == _e67) {
          $2GameUser.default.getInstance().setUnlocktili("get2", true);
          n.active = false;
          n.parent.getChildByName("b").active = true;
          this.tiliFly(1);
        } else if ("3" == _e67) {
          $2GameUser.default.getInstance().setUnlocktili("get3", true);
          n.active = false;
          n.parent.getChildByName("b").active = true;
          this.tiliFly(1);
        } else if ("4" == _e67) {
          this.root.getChildByName("4").getChildByName("choose2").active = false;
          this.root.getChildByName("4").getChildByName("choose").active = true;
          var _e68 = this.invite - this.lingqu;
          $2GameUser.default.getInstance().yilingqu += _e68;
          _e68 > 0 && this.tiliFly(_e68);
          this.reflash_yq();
          $2GameUser.default.getInstance().setUnlocktili("get4", true);
        } else if ("6" == _e67) {
          n.active = false;
          $2GameUser.default.getInstance().setUnlocktili("get6", true);
          this.root.getChildByName("6").getChildByName("choose2").active = false;
          this.root.getChildByName("6").getChildByName("b").active = true;
          this.tiliFly(1);
        } else if ("5" == _e67) {
          n.active = false, $2GameUser.default.getInstance().setUnlocktili("get5", true), this.root.getChildByName("5").getChildByName("choose2").active = false, this.root.getChildByName("5").getChildByName("b").active = true, this.tiliFly(1);
        }
      }
    }
  }, {
    key: "flash_3",
    value: function flash_3() {
      var e = $2GameUser.default.getInstance().getUnlocktili("3");
      var t = $2GameUser.default.getInstance().getUnlocktili("get3");
      this.root.getChildByName("3").getChildByName("choose").active = !e;
      this.root.getChildByName("3").getChildByName("choose2").active = e && !t;
      this.root.getChildByName("3").getChildByName("b").active = e && t;
    }
  }, {
    key: "flash_2",
    value: function flash_2() {
      var e = $2GameUser.default.getInstance().getUnlocktili("2");
      var t = $2GameUser.default.getInstance().getUnlocktili("get2");
      this.root.getChildByName("2").getChildByName("choose").active = !e;
      this.root.getChildByName("2").getChildByName("choose2").active = e && !t;
      this.root.getChildByName("2").getChildByName("b").active = e && t;
    }
  }, {
    key: "flash_1",
    value: function flash_1() {
      var e = $2GameUser.default.getInstance().getUnlocktili("1");
      var t = $2GameUser.default.getInstance().getUnlocktili("get1");
      this.root.getChildByName("1").getChildByName("choose").active = !e;
      this.root.getChildByName("1").getChildByName("choose2").active = e && !t;
      this.root.getChildByName("1").getChildByName("b").active = e && t;
    }
  }, {
    key: "init",
    value: function init() {
      var _this123 = this;
      this.flash_1();
      this.flash_2();
      this.flash_3();
      var e = $2GameUser.default.getInstance().getUnlocktili("0");
      var t = $2GameUser.default.getInstance().getUnlocktili("get0");
      this.root.getChildByName("0").getChildByName("choose").active = !e;
      this.root.getChildByName("0").getChildByName("choose2").active = e && !t;
      this.root.getChildByName("0").getChildByName("b").active = e && t;
      var n = $2GameUser.default.getInstance().getUnlocktili("6");
      var o = $2GameUser.default.getInstance().getUnlocktili("get6");
      this.root.getChildByName("6").getChildByName("choose").active = !n;
      this.root.getChildByName("6").getChildByName("choose2").active = n && !o;
      this.root.getChildByName("6").getChildByName("b").active = n && o;
      var i = $2GameUser.default.getInstance().getUnlocktili("5");
      var s = $2GameUser.default.getInstance().getUnlocktili("get5");
      console.log("unlock5lingqu5", i, s);
      this.root.getChildByName("5").getChildByName("choose").active = !i;
      this.root.getChildByName("5").getChildByName("choose2").active = i && !s;
      this.root.getChildByName("5").getChildByName("b").active = i && s;
      var r = $2GameUser.default.getInstance().openid;
      $2InteractiveMgr.default.getInteractiveStorage(r).then(function (e) {
        if (e.data && null != e.data.inviteRecords) {
          var _t63 = e.data.inviteRecords;
          console.log("邀请成功列表", _t63.length);
          if (_t63) {
            _this123.invite = _t63.length;
            _this123.lingqu = $2GameUser.default.getInstance().yilingqu;
            if (_this123.invite > _this123.lingqu) {
              $2GameUser.default.getInstance().setUnlocktili("4", true);
              $2GameUser.default.getInstance().setUnlocktili("get4", false);
              _this123.root.getChildByName("4").getChildByName("choose2").active = true;
              _this123.root.getChildByName("4").getChildByName("choose").active = false;
              var _e69 = "x".concat(_this123.invite - _this123.lingqu);
              _this123.tili4.string = _e69;
              console.log("邀请成功列表", _t63.length);
            }
            _this123.reflash_yq();
          }
        }
      });
    }
  }, {
    key: "reflash_yq",
    value: function reflash_yq() {
      this.yaoqing.string = "已邀请(".concat(this.invite, ")人已领取(").concat($2GameUser.default.getInstance().yilingqu, ")人");
    }
  }, {
    key: "init_libao",
    value: function init_libao(e) {
      var t = this.libao.getChildByName("arr");
      for (var _n56 = 0; _n56 < t.childrenCount; _n56++) {
        var _o122 = t.children[_n56];
        _o122.active = _o122.name == e;
      }
    }
  }, {
    key: "tiliFly",
    value: function tiliFly(e) {
      return cc__awaiter(this, undefined, undefined, /* */babel_regeneratorRuntime().mark(function _callee6() {
        return babel_regeneratorRuntime().wrap(function _callee6$(_context7) {
          while (1) {
            switch (_context7.prev = _context7.next) {
              case 0:
                $2GameUser.default.getInstance().tili += e;
                _context7.next = 3;
                return $2ccUtil.default.goldFlyEffect();
              case 3:
                $2EventCenter.default.postEvent($2EventDefine.default.GAME_TILI_INFO_UPDATE);
              case 4:
              case "end":
                return _context7.stop();
            }
          }
        }, _callee6);
      }));
    }
  }, {
    key: "createYXQBtn",
    value: function createYXQBtn(e) {
      var _this124 = this;
      if (null == window.wx) {
        return;
      }
      var t = window.wx.getSystemInfoSync;
      t.screenWidth;
      t.screenHeight;
      this.yxqBtn = window.wx.createGameClubButton({
        type: "image",
        image: "https://oppomini.eqmobi.com/stonesh/share/wxtm.png",
        style: {
          left: e.left,
          top: e.top,
          width: e.width,
          height: e.height
        },
        openlink: ""
      });
      this.yxqBtn.onTap(function () {
        $2GameUser.default.getInstance().setUnlocktili("5", true);
        _this124.root.getChildByName("5").getChildByName("choose").active = false;
        _this124.root.getChildByName("5").getChildByName("choose2").active = true;
        _this124.yxqBtn.destroy();
      });
    }
  }, {
    key: "showYXQ",
    value: function showYXQ() {
      null != this.yxqBtn && this.yxqBtn.show();
    }
  }, {
    key: "hideYXQ",
    value: function hideYXQ() {
      null != this.yxqBtn && this.yxqBtn.hide();
    }
  }, {
    key: "convertToWXRect",
    value: function convertToWXRect(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
      var n = {};
      console.log("微信获取尺寸");
      if (window.wx) {
        var _o123 = window.canvas.width / cc.winSize.width;
        var _i29 = window.canvas.height / cc.winSize.height;
        var _s12 = e.getComponent(cc.Widget);
        _s12 && _s12.updateAlignment();
        var _a22 = e.convertToWorldSpaceAR(cc.v2(0, 0));
        var _r4 = e.width * t;
        var _l3 = e.height * t;
        var _c2 = _r4 * _o123 / (window.canvas.width / window.wx.getSystemInfoSync().windowWidth);
        var _d = _l3 * _i29 / (window.canvas.height / window.wx.getSystemInfoSync().windowHeight);
        var _h = window.wx.getSystemInfoSync().windowWidth / (cc.winSize.width / _a22.x) - _c2 / 2;
        var _u = window.wx.getSystemInfoSync().windowHeight / (cc.winSize.height / (cc.winSize.height - _a22.y)) - _d / 2;
        n.left = _h;
        n.top = _u;
        n.width = _c2;
        n.height = _d;
        return n;
      }
      return n;
    }
  }]);
}($2BaseUIPopup.default);
def_UIPfree.className = "UIPfree";
cc__decorate([ccp_property(cc.Node)], def_UIPfree.prototype, "root", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIPfree.prototype, "libao", undefined);
cc__decorate([ccp_property(cc.Label)], def_UIPfree.prototype, "yaoqing", undefined);
cc__decorate([ccp_property(cc.ScrollView)], def_UIPfree.prototype, "scroller1", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIPfree.prototype, "scroll_content", undefined);
cc__decorate([ccp_property(cc.Label)], def_UIPfree.prototype, "tili4", undefined);
cc__decorate([ccp_property(cc.Prefab)], def_UIPfree.prototype, "icon", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIPfree.prototype, "tag_rectYXQ", undefined);
def_UIPfree = cc__decorate([ccp_ccclass], def_UIPfree);
exports.default = def_UIPfree;